<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Range</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Range 
            
                <span class="parent">&lt; 
                    
                    <a href="Type.html">ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Type</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../../../files/activerecord/lib/active_record/connection_adapters/postgresql/oid_rb.html">activerecord/lib/active_record/connection_adapters/postgresql/oid.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Range.html#method-i-extract_bounds">extract_bounds</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Range.html#method-i-infinity">infinity</a>,
              </li>
            
              
              <li>
                <a href="Range.html#method-i-infinity-3F">infinity?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Range.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Range.html#method-i-to_integer">to_integer</a>,
              </li>
            
              
              <li>
                <a href="Range.html#method-i-type_cast">type_cast</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>subtype</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(subtype)
            
            <a href="Range.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/9339005bb5504839e2a868f9510f0610da657400/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L104" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/oid.rb, line 104</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">subtype</span>)
  <span class="ruby-ivar">@subtype</span> = <span class="ruby-identifier">subtype</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-extract_bounds">
            
              <b>extract_bounds</b>(value)
            
            <a href="Range.html#method-i-extract_bounds" name="method-i-extract_bounds" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-extract_bounds_source')" id="l_method-i-extract_bounds_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/9339005bb5504839e2a868f9510f0610da657400/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L108" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-extract_bounds_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/oid.rb, line 108</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">extract_bounds</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span> = <span class="ruby-identifier">value</span>[<span class="ruby-number">1</span><span class="ruby-operator">..</span><span class="ruby-number">-2</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">','</span>)
  {
    <span class="ruby-identifier">from</span><span class="ruby-operator">:</span>          (<span class="ruby-identifier">value</span>[<span class="ruby-number">1</span>] <span class="ruby-operator">==</span> <span class="ruby-string">','</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">from</span> <span class="ruby-operator">==</span> <span class="ruby-string">'-infinity'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">infinity</span>(<span class="ruby-value">:negative</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">true</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">from</span>,
    <span class="ruby-identifier">to</span><span class="ruby-operator">:</span>            (<span class="ruby-identifier">value</span>[<span class="ruby-number">-2</span>] <span class="ruby-operator">==</span> <span class="ruby-string">','</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">to</span> <span class="ruby-operator">==</span> <span class="ruby-string">'infinity'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">infinity</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">to</span>,
    <span class="ruby-identifier">exclude_start</span><span class="ruby-operator">:</span> (<span class="ruby-identifier">value</span>[<span class="ruby-number">0</span>] <span class="ruby-operator">==</span> <span class="ruby-string">'('</span>),
    <span class="ruby-identifier">exclude_end</span><span class="ruby-operator">:</span>   (<span class="ruby-identifier">value</span>[<span class="ruby-number">-1</span>] <span class="ruby-operator">==</span> <span class="ruby-string">')'</span>)
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-infinity">
            
              <b>infinity</b>(options = {})
            
            <a href="Range.html#method-i-infinity" name="method-i-infinity" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-infinity_source')" id="l_method-i-infinity_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/9339005bb5504839e2a868f9510f0610da657400/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L118" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-infinity_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/oid.rb, line 118</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">infinity</span>(<span class="ruby-identifier">options</span> = {})
  <span class="ruby-operator">::</span><span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">INFINITY</span> * (<span class="ruby-identifier">options</span>[<span class="ruby-value">:negative</span>] <span class="ruby-operator">?</span> <span class="ruby-number">-1</span> <span class="ruby-operator">:</span> <span class="ruby-number">1</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-infinity-3F">
            
              <b>infinity?</b>(value)
            
            <a href="Range.html#method-i-infinity-3F" name="method-i-infinity-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-infinity-3F_source')" id="l_method-i-infinity-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/9339005bb5504839e2a868f9510f0610da657400/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L122" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-infinity-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/oid.rb, line 122</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">infinity?</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:infinite?</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">infinite?</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-to_integer">
            
              <b>to_integer</b>(value)
            
            <a href="Range.html#method-i-to_integer" name="method-i-to_integer" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-to_integer_source')" id="l_method-i-to_integer_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/9339005bb5504839e2a868f9510f0610da657400/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L126" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-to_integer_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/oid.rb, line 126</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">to_integer</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">infinity?</span>(<span class="ruby-identifier">value</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_i</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-type_cast">
            
              <b>type_cast</b>(value)
            
            <a href="Range.html#method-i-type_cast" name="method-i-type_cast" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-type_cast_source')" id="l_method-i-type_cast_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/9339005bb5504839e2a868f9510f0610da657400/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L130" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-type_cast_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/oid.rb, line 130</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">type_cast</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-string">'empty'</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Range</span>)

  <span class="ruby-identifier">extracted</span> = <span class="ruby-identifier">extract_bounds</span>(<span class="ruby-identifier">value</span>)

  <span class="ruby-keyword">case</span> <span class="ruby-ivar">@subtype</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:date</span>
    <span class="ruby-identifier">from</span>  = <span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">value_to_date</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:from</span>])
    <span class="ruby-identifier">from</span> <span class="ruby-operator">-=</span> <span class="ruby-number">1</span>.<span class="ruby-identifier">day</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">extracted</span>[<span class="ruby-value">:exclude_start</span>]
    <span class="ruby-identifier">to</span>    = <span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">value_to_date</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:to</span>])
  <span class="ruby-keyword">when</span> <span class="ruby-value">:decimal</span>
    <span class="ruby-identifier">from</span>  = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:from</span>].<span class="ruby-identifier">to_s</span>)
    <span class="ruby-comment"># FIXME: add exclude start for ::Range, same for timestamp ranges</span>
    <span class="ruby-identifier">to</span>    = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:to</span>].<span class="ruby-identifier">to_s</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-value">:time</span>
    <span class="ruby-identifier">from</span> = <span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">string_to_time</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:from</span>])
    <span class="ruby-identifier">to</span>   = <span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">string_to_time</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:to</span>])
  <span class="ruby-keyword">when</span> <span class="ruby-value">:integer</span>
    <span class="ruby-identifier">from</span> = <span class="ruby-identifier">to_integer</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:from</span>]) <span class="ruby-keyword">rescue</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">?</span> <span class="ruby-number">1</span> <span class="ruby-operator">:</span> <span class="ruby-number">0</span>
    <span class="ruby-identifier">from</span> <span class="ruby-operator">-=</span> <span class="ruby-number">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">extracted</span>[<span class="ruby-value">:exclude_start</span>]
    <span class="ruby-identifier">to</span>   = <span class="ruby-identifier">to_integer</span>(<span class="ruby-identifier">extracted</span>[<span class="ruby-value">:to</span>]) <span class="ruby-keyword">rescue</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">?</span> <span class="ruby-number">1</span> <span class="ruby-operator">:</span> <span class="ruby-number">0</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-operator">::</span><span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>, <span class="ruby-identifier">extracted</span>[<span class="ruby-value">:exclude_end</span>])
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    